﻿using System.Diagnostics;
using System.Web.Mvc;
using PartialViewResult = Ext.Net.MVC.PartialViewResult;
namespace Sharp.Portal.ExtNet.Filter
{
    /// <summary>
    /// 局部页过滤器
    /// </summary>
    [DebuggerStepThrough]
    public class PartialViewResultFilter : IResultFilter
    {
        /// <summary>
        /// OnResultExecuted
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnResultExecuted(ResultExecutedContext filterContext)
        {
        }

        /// <summary>
        /// OnResultExecuting
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnResultExecuting(ResultExecutingContext filterContext)
        {
            var request = filterContext.RequestContext;
            //var viewData = filterContext.Controller.ViewData;

            if (filterContext.Result is PartialViewResult partialViewResult)
            {
                if (!string.IsNullOrEmpty(request.HttpContext.Request.Params["containerId"]))
                {

                    partialViewResult.ContainerId = request.HttpContext.Request.Params["containerId"];
                    if (partialViewResult.RenderMode == Ext.Net.RenderMode.Auto)
                    {
                        partialViewResult.RenderMode = Ext.Net.RenderMode.AddTo;
                    }
                }
            }
        }


    }
}
